package qj.ps;

import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;

import qj.util.Cols;
import qj.util.IOUtil;

public class GenLog4jConfig {
	public static void main1(String[] args) throws Exception {
		gen(
				"decoupling-common-log", 
				"decoupling", 
				"%d{dd.MM.yyyy HH:mm:ss}|%c:%L|%M|%1.1p|%m | %n"
				);
		
		gen(
				"decoupling-process-log", 
				"decoupling-process", 
				"%d{dd MMM yyy HH:mm:ss}, %-6p %C:%M:%L %m %n"
				);
		
		gen(
				"db-request-log", 
				"db-request", 
				"%d{dd MMM yyy HH:mm:ss}, %-6p %C:%M:%L %m %n"
				);
		
		gen(
				"subsmngmnt-log", 
				"subsmngmnt", 
				"%d{dd MMM yyy HH:mm:ss}, %-6p %C:%M:%L %m %n"
				);
		
		gen(
				"ecom-provision-log", 
				"ecom-provision", 
				"%d{dd.MM.yyyy HH:mm:ss}|%c:%L|%M|%1.1p|%m | %n"
				);
		
		gen(
				"ecom-payment-log", 
				"ecom-payment", 
				"%d{dd.MM.yyyy HH:mm:ss}|%c:%L|%M|%1.1p|%m | %n"
				);
		gen(
				"ecom-notification-log", 
				"ecom-notification", 
				"%d{dd.MM.yyyy HH:mm:ss}|%c:%L|%M|%1.1p|%m | %n"
				);
		gen(
				"catalog-log", 
				"catalog", 
				"%d{dd.MM.yyyy HH:mm:ss}|%c:%L|%M|%1.1p|%m | %n"
				);

		gen(
				"central-config-log", 
				"central-config", 
				"%d{dd.MM.yyyy HH:mm:ss}|%c:%L|%M|%1.1p|%m | %n"
				);
		gen(
				"http-request-if", 
				"http-if", 
				"%d{dd.MM.yyyy HH:mm:ss}|%c:%L|%M|%1.1p|%m | %n"
				);

		
		
		
		
		
		
		gen(
				"selfcare", 
				"selfcare", 
				"%d{dd MMM yyy HH:mm:ss}, %-6p %C:%M:%L %m %n"
				);

		gen(
				"batch-log", 
				"batch", 
				"%d{dd MMM yyy HH:mm:ss}, %-6p %C:%M:%L %m %n"
				);

		gen(
				"ecom-core", 
				"ecom-core", 
				"%d{dd MMM yyy HH:mm:ss}, %-6p %C:%M:%L %m %n"
				);
	}
	public static void main(String[] args) throws Exception {

		gen(
				"ecom-core", 
				"ecom-core", 
				"%d{dd MMM yyy HH:mm:ss}, %-6p %C:%M:%L %m %n"
				);

	}

	private static void gen(String logRefName, String logFile, String pattern) throws IOException {
		Map<String, String> values = Cols.map(
				"logRefName", logRefName,
				"logFile", logFile,
				"pattern", pattern
				);
		
		
		String template = IOUtil.inputStreamToString(GenLog4jConfig.class.getResourceAsStream("genlog4j.xml"));
		
		for (Entry<String, String> entry : values.entrySet()) {
			template = template.replaceAll("\\$" + entry.getKey(), entry.getValue());
		}
		System.out.println(template);
	}
}
